<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/templates/tmpl_admin.xhtml">
	<ui:define name="centro">

		<h:form id="form">
			<p:dataTable id="listaPapel" var="papel" value="#{papelMBean.papeis}"
				paginator="true" rows="10"
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				rowsPerPageTemplate="5,10,15" emptyMessage="Nenhum papel cadastrado"
				filteredValue="#{papelMBean.papeisFiltro}" resizableColumns="true"
				selectionMode="single" rowKey="#{papel.id}"
				selection="#{papelMBean.papel}">

				<p:ajax event="rowSelect" update=":form:formulario" oncomplete="papelDialog.show()" listener="#{papelMBean.editar}" />

				<f:facet name="header">
					Lista de Papéis
				</f:facet>

				<p:column headerText="Código">
					<p:outputLabel value="#{papel.id}" />
				</p:column>

				<p:column headerText="Descrição" sortBy="#{papel.descricao}"
					filterBy="#{papel.descricao}" filterMatchMode="contains">
					<p:outputLabel value="#{papel.descricao}" />
				</p:column>

				<p:column headerText="Código Sistema">
					<p:outputLabel value="#{papel.codigoSistema}" />
				</p:column>

				<f:facet name="footer">
					<p:commandButton value="Novo" icon="ui-icon-plus" update=":form:formulario" actionListener="#{papelMBean.novo}" oncomplete="papelDialog.show()" />
				</f:facet>
			</p:dataTable>
			
			<p:dialog header="Papel" widgetVar="papelDialog" resizable="false"
				showEffect="clip" hideEffect="fold">
				<h:panelGrid id="formulario" columns="2" cellpadding="4">
					<p:outputLabel value="Descrição" />
					<p:inputText value="#{papelMBean.papel.descricao}" />

					<p:outputLabel value="Código Sistema" />
					<p:inputText value="#{papelMBean.papel.codigoSistema}" />

					<p:commandButton action="#{papelMBean.salvar}" value="Salvar" update=":form:listaPapel" oncomplete="papelDialog.hide()" />
					<p:commandButton action="#{papelMBean.deletar}" value="Deletar" rendered="#{papelMBean.acao == 'editar'}" update=":form:listaPapel" oncomplete="papelDialog.hide()" />
					
				</h:panelGrid>
			</p:dialog>

		</h:form>

	</ui:define>
</ui:composition>

</html>
